package com.sphd.emanu.activity.orderreceive;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.sphd.emanu.R;
import com.sphd.emanu.fragment.goodorder.GoodorderFragment;
import com.sphd.emanu.fragment.topuporder.TopuporderFragment;
import com.sphd.emanu.mvp.MVPBaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 接单
 *
 * @Author Hu
 * @Time 2017/4/17 -- 16:07.
 * @Email 87683202@qq.com
 */
public class OrderreceiveActivity extends MVPBaseActivity<OrderreceiveContract.View, OrderreceivePresenter> implements OrderreceiveContract.View {

    @BindView(R.id.good_order)
    TextView goodOrder;
    @BindView(R.id.topup_order)
    TextView topupOrder;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    GoodorderFragment goodorderFragment;
    TopuporderFragment topuporderFragment;
    Intent intent;
    Bundle bundle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orderreceive);
        ButterKnife.bind(this);
        initView();
        initEvent();
    }

    private void initEvent() {
        toolbar.setNavigationOnClickListener(v -> finish());
    }

    private void initView() {
        setTitleBar(toolbar, "");
        intent=getIntent();
        bundle=intent.getExtras();
        select(0);
    }

    private void select(int i) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        hidefragment(fragmentTransaction);
        switch (i) {
            case 0:
                if (goodorderFragment == null) {
                    goodorderFragment = new GoodorderFragment();
                    goodorderFragment.setArguments(bundle);
                    fragmentTransaction.add(R.id.content,goodorderFragment);
                }else {
                    fragmentTransaction.show(goodorderFragment);
                }
                break;
            case 1:
                if (topuporderFragment==null){
                    topuporderFragment=new TopuporderFragment();
                    topuporderFragment.setArguments(bundle);
                    fragmentTransaction.add(R.id.content,topuporderFragment);
                }else {
                    fragmentTransaction.show(topuporderFragment);
                }
                break;

        }
        fragmentTransaction.commit();
    }

    private void hidefragment(FragmentTransaction fragmentTransaction) {
        if (goodorderFragment!=null){
            fragmentTransaction.hide(goodorderFragment);
        }
        if (topuporderFragment!=null){
            fragmentTransaction.hide(topuporderFragment);
        }

    }


    @OnClick({R.id.good_order, R.id.topup_order})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.good_order:
                goodOrder.setTextSize(16);
                topupOrder.setTextSize(12);
                select(0);
                break;
            case R.id.topup_order:
                select(1);
                goodOrder.setTextSize(12);
                topupOrder.setTextSize(16);
                break;
        }
    }
}
